#ifndef MESSAGEWRAPPER_H
#define MESSAGEWRAPPER_H

#include "QXmppMessage.h"
#include <QMap>
#include <QDateTime>
#include <QVariant>
#include <QtDeclarative>

#include "msgitemmodel.h"
#include "msglistmodel.h"


class MyXmppClient;

class MeegimMessage
{
public:
    MeegimMessage() { dlr = false; msg = ""; id = ""; myMsg = false; }
    bool dlr;
    bool myMsg;
    QString id;
    QString msg;
    QDateTime date;
    void toString() {
        qDebug()<<"MSG: ["<<date.toString("hh:mm:ss")<<"] id:["<<id<<"] isMy:["<<myMsg<<"] dlr:["<<dlr<<"] txt:["<<msg<<"]";
    }
};

class MessageWrapper : public QObject
{
    Q_OBJECT
    QDeclarativeView *qmlObj;
    MsgListModel *mlm;

    QXmppMessage *xmppMessage;

    QVariantMap qmlBufOpenChats;

    void textMessage(const QXmppMessage &xmppMsg);
    void startWriteMessage(const QXmppMessage &xmppMsg);
    void pauseWriteMessage(const QXmppMessage &xmppMsg);

    /* "jid" => list of MeegimMessage */
    QMap<QString, QList<MeegimMessage>* > listOfChats;

public:
    explicit MessageWrapper(QObject *parent = 0);

    Q_INVOKABLE QVariantMap getOpenChats() const { return qmlBufOpenChats; }
    Q_INVOKABLE void initChat( QString jid );
    Q_INVOKABLE bool sendMyMessage( QString bareJid, QString msgBody );

    void removeListOfChat( QString &bareJid );
    
signals:
    void openChat(QString jid);
    void sendMyMsg( const QXmppPacket &xmppMsg );
    
public slots:
    void messageReceived( const QXmppMessage &xmppMsg );
    void messageDelivered( const QString &jid, const QString &id );
    
};

#endif // MESSAGEWRAPPER_H
